package com.example.factory.responsibility.chain.builder;

import com.example.factory.responsibility.chain.DefaultProcessSlotChain;
import com.example.factory.responsibility.chain.ProcessChain;
import com.example.factory.responsibility.slot.AbstractLinkedProcessorSlot;
import com.example.factory.responsibility.slot.ProcessorSlot;
import com.example.factory.responsibility.slot.StrategySlot;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

@Component
public class DefaultProcessChainBuilder implements SlotChainBuilder{
    @Autowired
    Map<String, StrategySlot> hashMap = new ConcurrentHashMap<>();
    @Override
    public ProcessChain builder() {
        DefaultProcessSlotChain slotChain = new DefaultProcessSlotChain();
        DefaultProcessSlotChain slotChain2 = new DefaultProcessSlotChain();
        List<ProcessorSlot> list = hashMap.values().stream().collect(Collectors.toList());
        for (ProcessorSlot p : list){
            slotChain.addLast((AbstractLinkedProcessorSlot<?>) p);
        }
        for (ProcessorSlot p : list){
            slotChain2.addLast((AbstractLinkedProcessorSlot<?>) p);
        }
        slotChain.addLast(slotChain2);
        return slotChain;
    }
}
